package solutions.leetcode.normal;

import solutions.lib.BaseSolution;

/**
 * @author lizhidong
 * <a href="https://leetcode.cn/problems/house-robber/">198. 打家劫舍</a>
 */
public class Solution198 extends BaseSolution {

    public int rob(int[] nums) {
        int r1 = 0, r2 = 0;
        for (int item : nums) {
            int not = Math.max(r1, r2);
            int rob = r1 + item;
            r1 = not;
            r2 = rob;
        }
        return Math.max(r1, r2);
    }

    public static void main(String[] args) {
        Solution198 solution = new Solution198();
        System.out.println(solution.rob(new int[] {
                2,7,9,3,1
        }));
    }
}